home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-05-23 | 2.1 KB | 84 lines |
- // FingerComponent
- // A very simple JFS client for fingering a user at an arbitrary host.
- // Makes use of /dev/TCP to get around applet socket restrictions
- import java.awt.*;
- import java.net.*;
- import java.io.*;
-
- public class FingerComponent extends JFScomponent
- {
- TextField host, user;
- TextArea result;
-
- FingerComponent()
- {
- // create UI
- setLayout(new BorderLayout());
- Panel top = new Panel();
- top.setLayout(new BorderLayout());
- Panel left = new Panel();
- left.setLayout(new GridLayout(2,1));
- left.add(new Label("Host"));
- left.add(new Label("Username"));
- top.add("West", left);
- Panel right = new Panel();
- right.setLayout(new GridLayout(2,1));
- right.add(host = new TextField());
- right.add(user = new TextField());
- top.add("Center", right);
- add("North", top);
- add("Center", result = new TextArea());
- result.setEditable(false);
- result.setFont(new Font("courier", Font.PLAIN, 10));
- }
-
- public boolean action(Event evt, Object obj)
- {
- if (evt.target == host || evt.target == user) {
- // Read from /dev/TCP
- Message head = new Message();
- String hoststr = host.getText().trim(),
- userstr = user.getText().trim();
- if (hoststr.length() == 0)
- return false; // no host given
- head.add("Host", hoststr);
- head.add("Port", "79");
- int fport;
- try fport = Integer.parseInt(client.devget("/dev/TCP", head).
- find("Port"));
- catch(RequestException e) {
- new ErrorWindow("Error fingering "+userstr+"@"+
- hoststr+" : "+e.getMessage());
- return false;
- }
-
- // Connect to finger
- Socket s = null;
- LineInputStream sin = null;
- LineOutputStream sout = null;
- try {
- s = new Socket(client.serverhost, fport);
- sin = new LineInputStream(s.getInputStream());
- sout = new LineOutputStream(s.getOutputStream());
- }
- catch(Exception e) {
- new ErrorWindow("Error connecting to server : "+
- e.getMessage());
- return false;
- }
- sout.puts(userstr);
- String res = "";
- try while(true) res += sin.gets()+"\n";
- catch(IOException e);
- result.setText(res);
- }
- return true;
- }
-
- Dimension wantedsize()
- {
- return new Dimension(500, 250);
- }
- }
-
-